///*
// *  Copyright 2019-2020 Zheng Jie
// *
// *  Licensed under the Apache License, Version 2.0 (the "License");
// *  you may not use this file except in compliance with the License.
// *  You may obtain a copy of the License at
// *
// *  http://www.apache.org/licenses/LICENSE-2.0
// *
// *  Unless required by applicable law or agreed to in writing, software
// *  distributed under the License is distributed on an "AS IS" BASIS,
// *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// *  See the License for the specific language governing permissions and
// *  limitations under the License.
// */
//package com.zyll.lp.controller;
//
//
//import com.zyll.book.aop.Log;
//import com.zyll.book.domain.SpUsers;
//import com.zyll.book.domain.dto.UserDto;
//import com.zyll.book.redis.RedisCRUD;
//import com.zyll.book.security.LoginUser;
//import com.zyll.book.service.SpUsersService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import lombok.RequiredArgsConstructor;
//import org.apache.commons.lang3.RandomStringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.ResponseEntity;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.context.SecurityContextHolder;
//import org.springframework.security.crypto.factory.PasswordEncoderFactories;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.util.DigestUtils;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.multipart.MultipartFile;
//
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//import java.util.List;
//
//@RestController
//@RequestMapping("auth")
//@RequiredArgsConstructor
//@Api(tags = "系统：系统授权接口")
//public class AuthorizationController {
//
//    private final AuthenticationManagerBuilder authenticationManagerBuilder;
//
//
//    private final SpUsersService userService;
//
//    @Autowired
//    RedisCRUD redisCRUD;
//
//    @PostMapping("/login")
//    public ResponseEntity login(@RequestBody UserDto userDto){
//        UsernamePasswordAuthenticationToken authenticationToken =
//                new UsernamePasswordAuthenticationToken(userDto.getUsername(),userDto.getPassword() );
//        Authentication authentication = authenticationManagerBuilder.getObject().authenticate(authenticationToken);
//        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
//
//        return ResponseEntity.ok(loginUser );
//
//    }
//    @PostMapping("/register")
//    public ResponseEntity register(@RequestBody SpUsers user){
//
//        PasswordEncoder passwordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
//        user.setUserPassword(passwordEncoder.encode(user.getUserPassword()
//        ));
//        user.setUserApi(DigestUtils.md5DigestAsHex(user.getUserName().getBytes()));
//        user.setUserPromoteCode(RandomStringUtils.randomAlphanumeric(15));
//
//        boolean save = userService.save(user);
//
//        return ResponseEntity.ok(save);
//
//    }
//
//    @Log("测试")
//    @PostMapping("/test")
//    public ResponseBody test(String str){
//
//        System.out.println();
//        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//        authentication.getPrincipal();
//
//        return ResponseBody.success(authentication);
//    }
//
//
//    @PostMapping("/test2")
//    public ResponseBody test2(){
//
//        List<SpUsers> list = userService.list();
//
//        return ResponseBody.success(list);
//
//    }
//
//    @PostMapping("/test3")
//    public ResponseBody test3(){
//
//        redisCRUD.set("test","14321");
//
//        String test = redisCRUD.get("test");
//        return ResponseBody.success(test);
//
//    }
//
//    @Log("单文件上传")
//    @ApiOperation(value = "单文件File上传")
//    @RequestMapping(value="/upload",method = RequestMethod.POST)
//    public ResponseBody upload( MultipartFile files, String title, HttpServletRequest request) throws IOException {
//
////        for (MultipartFile file:files
////             ) {
//
////            System.out.println(file.toString());
//            System.out.println(files.toString());
////        }
//        return ResponseBody.success();
//
//    }
//    @Log("多文件File上传")
//    @ApiOperation(value = "多文件File上传")
//    @PostMapping("uploads")
//    public ResponseBody uploads( MultipartFile[] file, String title, HttpServletRequest request) throws IOException {
//
////        for (MultipartFile file:files
////             ) {
//
////            System.out.println(file.toString());
//            System.out.println(file.toString());
////        }
//        return ResponseBody.success();
//
//    }
////
////
////    @PostMapping("redis1")
////    public ResultBody redis1(String key) throws IOException {
////        HashMap map = new HashMap();
////        map.put("t1",12312);
////        map.put("t2",14535);
////        map.put("t3",5644);
////        map.put("t4",63543);
////
////        redisValUtil.set(key,map);
////
////        return ResultBody.success();
////
////    }
////
////    @Autowired
////    RedisBaseUtil redisBaseUtil;
//
////    @Autowired
////    RedisValUtil redisBaseUtil;
//    @PostMapping("redis2")
//    public ResponseBody redis2(String key) throws IOException {
////        RedisBaseUtil redisBaseUtil = new RedisSetUtil();
////        RedisValUtil redisValUtil = new RedisValUtil();
////        redisValUtil.set(key,"测试");
////        redisValUtil.set(1,key,"测试",10);
////        redisValUtil.set(2,key,"测试",20);
////        redisValUtil.set(3,key,"测试",30);
////        redisValUtil.set(4,key,"测试",40);
////        redisValUtil.set(5,key,"测试",50);
//
//        return ResponseBody.success();
//
//    }
//
//    public static void main(String[] args) {
//
//        PasswordEncoder passwordEncoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
//        boolean b = passwordEncoder.upgradeEncoding("{SHA-256}");
//        String password = "123456";
//        String encode1 = passwordEncoder.encode(password);
//        System.out.printf(encode1);
//
//        String encode = passwordEncoder.encode(password);
//        boolean matches2 = passwordEncoder.matches(password, "{SHA-256}"+encode);
//        boolean matches3 = passwordEncoder.matches(password, "{bcrypt}$2a$10$U.6l2QiC.nPsp9qHh.DYkOMshoeGMcP3EOILzpS2joEsricCqLrN6");
//        boolean matches4 = passwordEncoder.matches(password, "{SHA-256}8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92");
//        System.out.println(encode);
//        System.out.println(matches2);
//        System.out.println(matches3);
//        System.out.println(matches4);
//    }
//}
